﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Collections;
using Webchatting.Common;
using Webchatting.Dal;

public partial class server_SearchGroup : System.Web.UI.Page
{
    public static ArrayList arrGroupIds = new ArrayList();
    public static ArrayList arrGroupNames = new ArrayList();
    public static ArrayList arrGroupOwners = new ArrayList();
    public static ArrayList arrGroupDess = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSerachGgroup_Click(object sender, EventArgs e)
    {
        OperationGroup Ogroup = new OperationGroup();
        string serachFriends = Ogroup.SearchGroup(txtSearchGroups.Text.Trim(), arrGroupIds, arrGroupNames, arrGroupOwners, arrGroupDess);

        ltlResult.Text = "<b>搜索结果：</b><br/>" + serachFriends;
        ltlText.Text = "<b>请选择要加入的群ID：</b>";

        ddlAddGroup.Visible = true;
        btnAddGroup.Visible = true;

        while (ddlAddGroup.Items.Count > 0)
        {
            ddlAddGroup.Items.RemoveAt(0);
        }

        for (int i = 0; i < arrGroupIds.Count; i++)
        {
            ddlAddGroup.Items.Add(new ListItem((string)arrGroupIds[i], (string)arrGroupIds[i]));
        }

    }

    protected void btnAddroup_Click(object sender, EventArgs e)
    {
        OperationGroup OGroup = new OperationGroup();

        int selected = ddlAddGroup.SelectedIndex;
        FormsIdentity id = (FormsIdentity)User.Identity;

        try
        {


            OGroup.AddGroupMum(arrGroupIds[selected].ToString(), id.Ticket.UserData.Split('@')[0], id.Ticket.UserData.Split('@')[1]);

            Response.Write("<script>alert('成功加入该群!');window.parent.location.href='RUIndex.aspx';</script>");
        }
        catch
        {
            Javascript.GoHistory(-1, "操作失败！", Page);
        }
    }
   
}
